package com.hghivln.controller.system;

import com.hghivln.aspectj.annotation.Log;
import com.hghivln.aspectj.enums.BusinessType;
import com.hghivln.pojo.dto.DeptDto;
import com.hghivln.pojo.vo.AjaxResult;
import com.hghivln.service.DeptService;
import com.hghivln.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;

@RestController
@RequestMapping("system/dept")
public class DeptController {

    @Autowired
    private DeptService deptService;

    /**
     * 分页查询
     */
    @GetMapping("listDeptForPage")
    public AjaxResult listDeptForPage(DeptDto deptDto) {
        return deptService.listDeptForPage(deptDto);
    }

    /**
     * 查询所有有效的科室信息
     */
    @GetMapping("selectAllDept")
    public AjaxResult selectAllDept() {
        return deptService.selectAllDept();
    }

    /**
     * 添加
     */
    @PostMapping("addDept")
    @Log(title = "添加科室",businessType = BusinessType.INSERT)
    public AjaxResult addDept(@Validated DeptDto deptDto) {
        deptDto.setSimpleUser(ShiroUtils.getCurrentSimpleUser());
        return AjaxResult.toAjax(deptService.addDept(deptDto));
    }

    /**
     * 修改
     */
    @PutMapping("updateDept")
    @Log(title = "修改科室",businessType = BusinessType.UPDATE)
    public AjaxResult updateDept(@Validated DeptDto deptDto) {
        deptDto.setSimpleUser(ShiroUtils.getCurrentSimpleUser());
        return AjaxResult.toAjax(deptService.updateDept(deptDto));
    }

    /**
     * 删除
     */
    @DeleteMapping("deleteDeptByIds/{ids}")
    @Log(title = "删除科室",businessType = BusinessType.DELETE)
    public AjaxResult deleteDeptByIds(@PathVariable @Validated @NotEmpty(message = "要删除的科室ID不能为空")Long[] ids) {
        return AjaxResult.toAjax(deptService.deleteDeptByIds(ids));
    }

    /**
     * 根据ID查询一个字典信息
     */
    @GetMapping("getDeptById/{id}")
    public AjaxResult getDeptById(@PathVariable @Validated @NotEmpty(message = "科室ID不能为空") Long id) {
        return AjaxResult.success(deptService.getDeptById(id));
    }



}
